import { loginAPI } from '@/api'

const state = {
  token: localStorage.getItem('TOKEN') || ''

}
const mutations = {
  GETTOKEN (state, token) {
    state.token = token
    localStorage.setItem('TOKEN', token)
  }
}

const actions = {
  async confirmLogin (store, value) {
    try {
      const res = await loginAPI(value)
      const { token } = res.data.body
      store.commit('GETTOKEN', token)
      return Promise.resolve(res)
    } catch (error) {
      return Promise.reject(error)
    }
  }
}

const getters = {

}

export default {
  state,
  mutations,
  actions,
  getters
}
